package com.example.ali.sim;

import android.provider.Settings;
import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.telephony.IccOpenLogicalChannelResponse;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.EditText;
import android.content.Context;
import android.telephony.TelephonyManager;
import android.widget.TextView;


public class MainActivity extends ActionBarActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        TextView devidView = (TextView) findViewById(R.id.devid);
        TelephonyManager telephonyManager = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);

        //String  identifier = Settings.Secure.getString(this.getContentResolver(), Settings.Secure.ANDROID_ID);
        devidView.setText( getDeviceID(telephonyManager));

        //devidView(TestAT(telephonyManager));
    }
    String   TestAT(TelephonyManager tm) {
        String str="";
        ///return str;

        String cmd= "AT+CCHO";
        IccOpenLogicalChannelResponse rsp = tm.iccOpenLogicalChannel (cmd);
        if (rsp!=null) {
            str = rsp.toString();
        }
         return str;

    }
    String getDeviceID(TelephonyManager tm) {
        String str = "\n";

        str += "DeviceId (IMEI) =" + tm.getDeviceId() + "\n";
        str += "SubscriberId (IMSI) =" + tm.getSubscriberId() + "\n";
        str += "SimSerialNumber = " + tm.getSimSerialNumber() + "\n";
        str += "NetworkCountryIso =" + tm.getNetworkCountryIso() + "\n";
        str += "NetworkOperator =" + tm.getNetworkOperator() + "\n";
        str += "NetworkOperatorName =" + tm.getNetworkOperatorName() + "\n";
        str += " NetworkType = " + tm.getNetworkType() + " \n ";

        str += "SimState =" + tm.getSimState() + "\n";
        str += " SimCountryIso = " + tm.getSimCountryIso() + " \n ";
        str += " SimOperator = " + tm.getSimOperator() + " \n ";
        str += " SimOperatorName = " + tm.getSimOperatorName() + " \n ";

        str += "DeviceSoftwareVersion =" + tm.getDeviceSoftwareVersion() + "\n";
        str += "Line1Number =" + tm.getLine1Number() + "\n";
        str += " PhoneType = " + tm.getPhoneType() + " \n ";

        str += "VoiceMailNumber =" + tm.getVoiceMailNumber() + "\n";
        return str;
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.menu_main, menu);
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        // Handle action bar item clicks here. The action bar will
        // automatically handle clicks on the Home/Up button, so long
        // as you specify a parent activity in AndroidManifest.xml.
        int id = item.getItemId();

        //noinspection SimplifiableIfStatement
        if (id == R.id.action_settings) {
            return true;
        }

        return super.onOptionsItemSelected(item);
    }
}
